<script type="text/javascript">

jQuery(function($) {
					 
	$("#objects").tableDnD({
	    onDragClass: "dragging",
	    onDrop: function(table, row) {
			$.post("sort-manual/", {order:$(table).tableDnDSerialize()});
	    },
		dragHandle: "dragHandle"
	});
	
	$("#objects .object").hover(function() {
          $(this).addClass('showDragHandle');
	    }, function() {
          $(this).removeClass('showDragHandle');
	    }
	);
	
	$("#objects .object a.button").click(function() {
		var self = $(this), href = self.attr("href"), parent = self.parents(".object"), id = parent.attr("id").substr(4), title = self.attr("title").match(/(«.*»)/)[0], attr = parent.find("input.attr");

		if (self.hasClass('visible')) {
			$.post(href);
			self.removeClass('visible').addClass('hidden').attr("title", "показать " + title).attr("href", href.replace("hide", "show"));
			attr.val(attr.val() & !1);
			return false;
		} else

		if (self.hasClass('hidden')) {
			$.post(href);
			self.removeClass('hidden').addClass('visible').attr("title", "скрыть " + title).attr("href", href.replace("show", "hide"));
			attr.val(attr.val() | 1);
			return false;
		} else

		if (self.hasClass('kill')) {
			if (confirm('Are you sure you want to kill ' + title + '?')) {
				$.post(href);
				parent.remove();
			}
			return false;
		}

		return true;
	});
	
});

</script>

<h3>Add review</h3>

<form action="" method="post">
	<p><label>Name<br />
		<input type="text" name="title" class="wide" /></label>
		
		<input type="submit" name="create_object" value="Add" /></p>
</form>


<? if (sizeof($d = dat('objects'))) { 

	?><table class="adm dnd" id="objects"><thead><tr class="nodrag nodrop">
	<td>Edit</td><td></td><td>Name</td></tr></thead><tbody><?

	foreach($d as $a) {
		?><tr id="obj-<?=$a[id]?>" class="object">
			<td>
				<? if ($a['attr'] & AA_VISIBLE) { ?>
					<a title='Disable «<?=$a['name']?>»' class="button visible" href="hide-<?=$a[id]?>/"><span>Disable</span></a>
				<? } else { ?>
					<a title='Enable «<?=$a['name']?>»' class="button hidden" href="show-<?=$a[id]?>/"><span>Enable</span></a>
				<? } ?>
				<a title='Edit «<?=$a['name']?>»' class="button edit" href="edit-<?=$a[id]?>/"><span>Edit</span></a>

				<a title='Kill «<?=$a['name']?>»' class="button kill" href="delete-<?=$a[id]?>/"><span>Kill</span></a>			
			</td>
			<td class="dragHandle"><input type="hidden" class="attr" name="attr[<?=$a['id']?>]" value="<?=$a['attr']?>" /></td>
			<td><a href="edit-<?=$a['id']?>/" title='Edit «<?=$a['name']?>»'><?=$a['name']?></a></td>

		  </tr>
		<?
	}

	?></tbody></table><?

} else {

	?>No reviews yet.<?

} ?>
